package com.itboy.mall.sms.memberprice.controller;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itboy.mall.sms.memberprice.domain.MallMemberPrice;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.sms.memberprice.vo.MallMemberPriceVo;
import com.itboy.mall.sms.memberprice.bo.MallMemberPriceQueryBo;
import com.itboy.mall.sms.memberprice.bo.MallMemberPriceAddBo;
import com.itboy.mall.sms.memberprice.bo.MallMemberPriceEditBo;
import com.itboy.mall.sms.memberprice.service.IMallMemberPriceService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商品会员价格Controller
 *
 * @author itboy
 * @date 2021-08-08
 */
@Validated
@Api(value = "商品会员价格控制器", tags = {"商品会员价格管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/memberPrice")
public class MallMemberPriceController extends BaseController {

    private final IMallMemberPriceService iMallMemberPriceService;

    /**
     * 查询商品会员价格列表
     */
    @ApiOperation("查询商品会员价格列表")
    @PreAuthorize("@ss.hasPermi('mall:memberPrice:list')")
    @GetMapping("/list")
    public TableDataInfo<MallMemberPriceVo> list(@Validated MallMemberPriceQueryBo bo) {
        return iMallMemberPriceService.queryPageList(bo);
    }

    /**
     * 导出商品会员价格列表
     */
    @ApiOperation("导出商品会员价格列表")
    @PreAuthorize("@ss.hasPermi('mall:memberPrice:export')")
    @Log(title = "商品会员价格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallMemberPriceVo> export(@Validated MallMemberPriceQueryBo bo) {
        List<MallMemberPriceVo> list = iMallMemberPriceService.queryList(bo);
        ExcelUtil<MallMemberPriceVo> util = new ExcelUtil<MallMemberPriceVo>(MallMemberPriceVo.class);
        return util.exportExcel(list, "商品会员价格");
    }

    /**
     * 获取商品会员价格详细信息
     */
    @ApiOperation("获取商品会员价格详细信息")
    @PreAuthorize("@ss.hasPermi('mall:memberPrice:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallMemberPriceVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallMemberPriceService.queryById(id));
    }

	/**
	 * 按skuId获取商品会员价格详细信息集合
	 */
	@ApiOperation("按skuId获取商品会员价格详细信息集合")
	@GetMapping("/queryMemberPriceBySkuId/{skuId}")
	public AjaxResult<List<MallMemberPrice>> queryMallMemberPriceBySkuId(@NotNull(message = "skuId不能为空")
												 @PathVariable("skuId") Long skuId) {
		return AjaxResult.success(iMallMemberPriceService.list(new LambdaQueryWrapper<MallMemberPrice>().eq(MallMemberPrice::getSkuId,skuId)));
	}

    /**
     * 新增商品会员价格
     */
    @ApiOperation("新增商品会员价格")
    @PreAuthorize("@ss.hasPermi('mall:memberPrice:add')")
    @Log(title = "商品会员价格", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallMemberPriceAddBo bo) {
        return toAjax(iMallMemberPriceService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改商品会员价格
     */
    @ApiOperation("修改商品会员价格")
    @PreAuthorize("@ss.hasPermi('mall:memberPrice:edit')")
    @Log(title = "商品会员价格", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallMemberPriceEditBo bo) {
        return toAjax(iMallMemberPriceService.updateByEditBo(bo) ? 1 : 0);
    }

	/**
	 * 修改商品会员价格
	 */
	@ApiOperation("修改商品会员价格")
	@PreAuthorize("@ss.hasPermi('mall:memberPrice:edit')")
	@Log(title = "商品会员价格", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/batchEdit")
	public AjaxResult<Void> batchEdit(@Validated @RequestBody List<MallMemberPrice> bo) {
		return toAjax(iMallMemberPriceService.updateBatchById(bo) ? 1 : 0);
	}

    /**
     * 删除商品会员价格
     */
    @ApiOperation("删除商品会员价格")
    @PreAuthorize("@ss.hasPermi('mall:memberPrice:remove')")
    @Log(title = "商品会员价格" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallMemberPriceService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
